package com.jm.product.entity;

import java.io.Serializable;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.google.common.collect.Lists;
/**
 * 商品分类Entity
 * @author sunshine
 * @version 2017-07-04
 */
@Entity
@Table(name = "es_goods_cat")
@Cache(region = "com.jm.cache", usage = CacheConcurrencyStrategy.READ_WRITE)
public class GoodsCat extends IdEntity<Integer> implements Serializable {
	
	private static final long serialVersionUID = 1L;
	
    @Column(name="name")
	private String name;//名称
    @Column(name="cat_path")
	private String catPath;//cat_path
    @Column(name="goods_count")
	private Integer goodsCount;//goods_count
    @Column(name="cat_order")
	private Integer catOrder;//排序
//    @Column(name="type_id")
//	private Integer typeId;//类型
    @Column(name="list_show")
	private String listShow;//是否显示
    @Column(name="image")
	private String image;//image
    
    @ManyToOne
    @JoinColumn(name="type_id")
    private GoodsType goodsType;

    @ManyToOne
    @JoinColumn(name="parent_id")
    private GoodsCat parent;

    @OneToMany(mappedBy="parent", fetch=FetchType.LAZY, cascade=CascadeType.ALL)
    private List<GoodsCat> children = Lists.newArrayList();

	public GoodsCat() {
		super();
	}
	
	/**
	*
	* get 名称
	*
	* return name
	*/
	public String getName() {
		return this.name;
	}
	
	/**
	 * 
	 * set 名称
	 * 
	 * @param name
	 */
	public void setName(String name) {
		this.name = name;
	}
	/**
	*
	* get cat_path
	*
	* return catPath
	*/
	public String getCatPath() {
		return this.catPath;
	}
	
	/**
	 * 
	 * set cat_path
	 * 
	 * @param catPath
	 */
	public void setCatPath(String catPath) {
		this.catPath = catPath;
	}
	/**
	*
	* get goods_count
	*
	* return goodsCount
	*/
	public Integer getGoodsCount() {
		return this.goodsCount;
	}
	
	/**
	 * 
	 * set goods_count
	 * 
	 * @param goodsCount
	 */
	public void setGoodsCount(Integer goodsCount) {
		this.goodsCount = goodsCount;
	}
	/**
	*
	* get 排序
	*
	* return catOrder
	*/
	public Integer getCatOrder() {
		return this.catOrder;
	}
	
	/**
	 * 
	 * set 排序
	 * 
	 * @param catOrder
	 */
	public void setCatOrder(Integer catOrder) {
		this.catOrder = catOrder;
	}
	
	public GoodsType getGoodsType() {
		return goodsType;
	}

	public void setGoodsType(GoodsType goodsType) {
		this.goodsType = goodsType;
	}

	/**
	*
	* get 是否显示
	*
	* return listShow
	*/
	public String getListShow() {
		return this.listShow;
	}
	
	/**
	 * 
	 * set 是否显示
	 * 
	 * @param listShow
	 */
	public void setListShow(String listShow) {
		this.listShow = listShow;
	}
	/**
	*
	* get image
	*
	* return image
	*/
	public String getImage() {
		return this.image;
	}
	
	/**
	 * 
	 * set image
	 * 
	 * @param image
	 */
	public void setImage(String image) {
		this.image = image;
	}


    public GoodsCat getParent() {
        return parent;
    }

    public void setParent(GoodsCat parent) {
        this.parent = parent;
    }

    public List<GoodsCat> getChildren() {
        return children;
    }

    public void setChildren(List<GoodsCat> children) {
        this.children = children;
    }
	
	@Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((id == null) ? 0 : id.hashCode());
        result = prime * result + ((name == null) ? 0 : name.hashCode());
        result = prime * result + ((catPath == null) ? 0 : catPath.hashCode());
        result = prime * result + ((goodsCount == null) ? 0 : goodsCount.hashCode());
        result = prime * result + ((catOrder == null) ? 0 : catOrder.hashCode());
        result = prime * result + ((listShow == null) ? 0 : listShow.hashCode());
        result = prime * result + ((image == null) ? 0 : image.hashCode());
        return result;
    }
	
    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (obj == null)
            return false;
        if (getClass() != obj.getClass())
            return false;
        GoodsCat other = (GoodsCat) obj;
        if (id == null) {
            if (other.id != null)
                return false;
        } else if (!id.equals(other.id))
            return false;
        if (name == null) {
            if (other.name != null)
                return false;
        } else if (!name.equals(other.name))
            return false;
        if (catPath == null) {
            if (other.catPath != null)
                return false;
        } else if (!catPath.equals(other.catPath))
            return false;
        if (goodsCount == null) {
            if (other.goodsCount != null)
                return false;
        } else if (!goodsCount.equals(other.goodsCount))
            return false;
        if (catOrder == null) {
            if (other.catOrder != null)
                return false;
        } else if (!catOrder.equals(other.catOrder))
            return false;
        if (listShow == null) {
            if (other.listShow != null)
                return false;
        } else if (!listShow.equals(other.listShow))
            return false;
        if (image == null) {
            if (other.image != null)
                return false;
        } else if (!image.equals(other.image))
            return false;
        return true;
    }
	
 	@Override
    public String toString() {
        return "GoodsCat [id=" + id + ",name=" + name + ",catPath=" + catPath + ",goodsCount=" + goodsCount + ",catOrder=" + catOrder + ",listShow=" + listShow + ",image=" + image + "]";
    }
}


